package com.training1.core.modules.service;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.training1.core.common.service.CrudService;
import com.training1.core.common.utils.DateUtils;
import com.training1.core.common.utils.excel.ExcelUtil;
import com.training1.core.entity.MemberEntity;
import com.training1.core.entity.PaymentEntity;
import com.training1.core.entity.SystemUserEntity;
import com.training1.core.modules.dao.PaymentDao;

@Service
@Transactional
public class PaymentService extends CrudService<PaymentDao,PaymentEntity>{
	
	
	@Resource
	private PaymentDao paymentDao;
	
	
	
	public List<PaymentEntity> findPayment(Map<String, Object> param){
		return paymentDao.findList(param);
	}
	
	/**
	 * 查找所有的开单中心
	 * @param param
	 * @return
	 */
	public List<SystemUserEntity> findCenter(Map<String, Object> param){
		return paymentDao.findCenter(param);
	
	}
	/**
	 * 查询总金额
	 * @param param
	 * @return
	 */
	public PaymentEntity findAllCash(Map<String, Object> param){
		return paymentDao.findAllCash(param);
		
	}

	/**
	 * 导出excel
	 * @param response
	 * @param param
	 */
	public void export(HttpServletResponse response,Map<String, Object> param) {
		List<PaymentEntity> pList = paymentDao.findexportList(param);//根据dao中的内容用方法
		//设置列标题
		List<String> excelHead = new ArrayList<String>();
		excelHead.add("订单编号");
		excelHead.add("会员姓名");
		excelHead.add("会员手机号");
		excelHead.add("开单中心");
		excelHead.add("支付类型");
		excelHead.add("发生时间");
		excelHead.add("支付金额");
		
		//设置内容
		List<List<String>> dataList = new ArrayList<List<String>>();
		for(PaymentEntity p : pList){
			List<String> data = new ArrayList<String>();
			data.add(p.getOrderNumber());
			data.add(p.getMemberName());
			data.add(p.getCellPhone());
			data.add(p.getUserName());
			data.add(p.getPaymentType().toString());
			data.add(p.getPaymentTime().toString());
			data.add(p.getCash().toString());
		
			dataList.add(data);
		}
		
		//设置文件名
		String fileName;
		String sheetName = "sheet1";
		String titleName;
		fileName = "财务出表_"+DateUtils.getDate().replace("-", "");
		titleName = "财务出表_"+DateUtils.getDate().replace("-", "");
		
		ExcelUtil.exportExcel(response, excelHead, dataList, fileName, sheetName,titleName);
	}
	
	/**
	 * 查询报表的数据
	 * @param param
	 * @return
	 */
	public List<PaymentEntity> findReport(){
		return paymentDao.findReport();
		
	}
}
